/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package be.hogent.iii.project.client.gui.gameroom;

import be.hogent.iii.project.common.game.objecten.Spel;
import be.hogent.iii.project.common.game.objecten.Speler;
import java.awt.Dimension;
import java.util.ArrayList;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 *
 * @author jef donders
 */
public class TabbedPanePanel extends JPanel  implements ChangeListener {

    private JTabbedPane tabbedPane;
    private GameRoomGui ouder;
    private LijstPanel spelersPanel;
    private LijstPanel gamesPanel;
    private Dimension size;
    private ArrayList<Spel> spellen;
    private ArrayList<Speler> spelers;

    public TabbedPanePanel(GameRoomGui ouder, Dimension size) {
        this.ouder = ouder;
        this.size = size;
        setBackground(new java.awt.Color(0, 0, 0));
        setForeground(new java.awt.Color(255, 255, 255));
        
        tabbedPane = new JTabbedPane();
        tabbedPane.addChangeListener(this);

        add(tabbedPane);
    }

    public void stateChanged(ChangeEvent e) {
        ouder.setInfoGamePanel(tabbedPane.getTitleAt(tabbedPane.getSelectedIndex()));
        //System.out.println(""+tabbedPane.getTitleAt(tabbedPane.getSelectedIndex()));
    }
    
    public void maakLijstGames(ArrayList<Spel> spellen){
        this.spellen = spellen;
        String [] namen = new String[spellen.size()];
        for (int i=0;i<spellen.size();i++){
            namen[i] = spellen.get(i).getNaam();
        }
        if (gamesPanel != null){
            tabbedPane.remove(gamesPanel);
        }
        gamesPanel = new LijstPanel(ouder,"Games", size, namen, "");
        
        tabbedPane.add(gamesPanel, "Games");
    }
    
    public void maakLijstSpelers(ArrayList<Speler> spelers){
        this.spelers = spelers;
        String [] namen = new String[spelers.size()];
        for (int i=0;i<spelers.size();i++){
            namen[i] = spelers.get(i).getNick();
            System.out.println("speler in mainchat: " +spelers.get(i).getNick() );
        }
        if (spelersPanel != null)
            tabbedPane.remove(spelersPanel);
        spelersPanel = new LijstPanel(ouder, "Spelers", size, namen, ouder.getSpeler().getNick());
        tabbedPane.add(spelersPanel, "Spelers");
    }
    
    public Spel getSpel(int n){
        System.out.println("opvraging van een spel: " + n + "  " + spellen.get(n).getNaam());
        return spellen.get(n);
    }

}
